
#生成模型
x <-subset(iris, select =-Species)
model.Kmeans <-kmeans(x, centers=3)

#生成混淆矩阵
table(model.Kmeans$cluster, iris$Species)

#计算距离
centers<-model.Kmeans$centers[model.Kmeans$cluster,]
distances<-sqrt(rowSums(x-centers)^2)

#打印结果
outlines <- order(distances,decreasing = TRUE)[1:5]
print(x[outlines,])